<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding: 0px;">
		<div class="easyui-layout" style="width:100%;height:600px;">
			<div data-options="region:'center'">
				<div>
					<table id="dg" style="width: 100%;" class="table_style">
					</table>
				</div>
			</div>
		</div>
		<div id="toolbar"></div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 100%;height: 100%;" frameborder="0" scrolling="yes"></iframe>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/Role/RoleFunction.js"></script>
	<script type="text/javascript">
		var toolbarType = TOOLBAR_ADD + TOOLBAR_DELETE;
		var content = ""; /*定义一个空的content*/
		content = AddToolBar(toolbarType);
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/

		/*添加信息*/
		function newdata() {
			$.messager.prompt({
				title: '新建角色',
				msg: '请输入角色名称',
				fn: function(r) {
					if(r) {
						var _url = "";
						var data = new Object();
						data.ROLE_NAME = r;
						////初始化object的元素
						for(var i = 0; i < rightList.length; i++) {
							data[rightList[i]] = "";
						}

						data.Rights = "";
						_url = RemoteLinkAddress + "/role/save.do";
						$.post(_url, data,
							function(result) {
								if(result.msg == "success") {
									$('#dg').datagrid('reload');
									$.messager.alert("提示", "保存成功");
								} else {
									$.messager.alert({ // show error message
										title: '错误',
										msg: result.msg
									});
								}
							},
							'json');
					}
				}
			});
		}
		$('#dg').datagrid({
			url: RemoteLinkAddress + '/role/list.do',
			toolbar: '#toolbar',
			method: 'get',
			pagination: 'true',
			rownumbers: 'true',
			autoRowHeight: 'true',
			singleSelect: 'true',
			fitColumns: 'false',
			height: 500,
			/*表格中的列名以及各自列名的ID*/
			columns: [
				[{
					field: 'ID',
					title: 'ID',
					width: '10%',
					align: 'center'
				}, {
					field: 'ROLE_NAME',
					title: '角色',
					width: '30%',
					align: 'center'
				}, {
					field: 'CHA',
					title: '查看',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_CHA,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'ADD',
					title: '新建',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_ADD,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'EDIT',
					title: '编辑',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_EDIT,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'DEL',
					title: '删除',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_DEL,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'SH',
					title: '审核',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_SH,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'QS',
					title: '弃审',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_QS,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'DC',
					title: '导出',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_DC,' + row.ID + ')">编辑</a>';
					}
				}, {
					field: 'DX',
					title: '短信',
					width: '5%',
					align: 'center',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openDialog(DATAGRID_TOOL_DX,' + row.ID + ')">编辑</a>';
					}
				}, ]
			],
		});

		function destroy() {
			var rowdata = $('#dg').datagrid('getSelected');
			if(!rowdata) {
				$.messager.alert('Info', "请选择你需要修改数据"); /*判断是否有行被选中，如果没有，则弹出警告框，提示用户修改数据*/
				return;
			}
			if(rowdata) {
				$.messager.confirm('Confirm', '是否删除', function(r) {
					if(r) {
						$.post(RemoteLinkAddress + "/role/delete.do", {
								ID: rowdata.ID,
							},
							function(result) {
								if(result.msg == "success") {
									$('#dg').datagrid('reload');
									$.messager.alert({
										title: '成功',
										msg: '删除成功',
									});
								} else {
									$.messager.alert({ // show error message
										title: 'Error',
										msg: result.msg
									});
								}
							},
							'json');
					}
				});
			}

		}

		function openDialog(type, ID) {
			DialogWidth = 300;
			DialogHeight = 400;
			var pLocation = "UI/Common/roleManager/roleManager.html?type=" + type + "&ID=" + ID;
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), rightZWArray[type], DialogWidth, DialogHeight);
			AddDialog.dialog('open');
		}

		function dialogClose() {
			AddDialog.dialog('close');
		}
	</script>

</html>